<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/style.css"/>
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/wallet.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" href="JavaScript:history.go(-1)"></a>
		    <h1 class="mui-title">绑定银行卡</h1>
		</header>
		<div class="mui-content">
		    <ul class="bank_list">
		    	<li class="clearfix">
		    		<label>开户行</label>
		    		<input type="text" id="bank_name" placeholder="请输入开户银行" />
		    	</li>
		    	<li class="clearfix">
		    		<label>卡&nbsp;&nbsp;&nbsp;号</label>
		    		<input type="text" id="bank_num" placeholder="请输入银行卡号" />
		    	</li>
		    	<li class="clearfix">
		    		<label>开户人</label>
		    		<input type="text" id="user_name" placeholder="请输入开户人姓名" />
		    	</li>
		    	<li class="special clearfix">
		    		<label>验证码</label>
		    		<input type="text" id='yzm'  placeholder="请输入验证码" />
		    		<a href="javascript:;" id="send_code">获取验证码</a>
		    	</li>
		    </ul>
		    <div class="wallet_btn"><a href="javascript:;" id="btn">确认</a></div>
		</div>
	</body>
</html>
<script src="../js/mui.min.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script type="text/javascript">
	mui.init()
	var send_code = $('#send_code');
	//true就是可以发送
	var onoff = true;
	var member = JSON.parse(localStorage.getItem("member"));
	var phone = member['mobile'];
	var btn = $('#btn');
	$.ajax({
			url: APP.api_url + 'wallet/add_bank',
			data: {
				uid			: getUid(),
				token		: get_token,
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				if(data.code == 200) {
					var json = data.data;
					$("#bank_name").val(json.bank_account); 
					$("#bank_num").val(json.card_no); 
					$("#user_name").val(json.bank_username);
				}else{
					console.log(data.msg);
				}
			}
		})
	
	//发送验证码
	send_code.click(function() {
		//false就不能发送
		if(!onoff) {
			return;
		}
		onoff = false;
		
		$.ajax({
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: APP.api_url + 'System/get_login_sms_',
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg);
				var num = 60;
				var timer = setInterval(function() {
					num--;
					if(num == 0) {
						send_code.html('发送验证码');
						//send_code.innerHTML = '发送验证码';
						//定时器停了
						clearInterval(timer);
						onoff = true;
					} else {
						send_code.html(num + 'S');
					}
				}, 1000); // 1000 毫秒==1秒
			}
		})

	});
	//注册
	btn.click(function() {
		var bank_name = $("#bank_name").val();
		var bank_num = $("#bank_num").val();
		var user_name = $("#user_name").val();
		var input_code = $("#yzm").val();
		
		if(bank_name.trim() == '') {
			layer.msg('开户银行不能为空');
			return;
		}
		
		if(bank_num.trim() == '') {
			layer.msg('银行卡号不能为空');
			return;
		}
		
		if(user_name.trim() == '') {
			layer.msg('开户人不能为空');
			return;
		}
		
		if(input_code.trim() == '') {
			layer.msg('验证码不能为空');
			return;
		}
		btn.disabled = true;
		setTimeout(function() {
			btn.disabled = false;
		}, 1500);
		//写入数据库
		$.ajax({
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: APP.api_url + 'wallet/add_bank',
			//请求的过程中传递过去的参数 json
			data: {
				bank_name	: bank_name,
				bank_num 	: bank_num,
				user_name	: user_name,
				verifycode	: input_code,
				uid			: getUid(),
				token		: get_token,
				mobile		: getUserMobile()
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg);
				if(data.code == 200) {
					layer.msg('绑定银行卡成功！', {
						  time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							location.href="index.html";
						});
				}else{
					console.log(data.msg);
				}
			}
		})
	});
</script>